function [CBF,DT] = calCBF_CMF(obj,x,A, D,AmplitudeD,deltat_Dict)

% if nargin < 3
%     % Construct the dictionary
%     CBF_Dict = [1];
%     deltat_Dict = [0.1:0.01:2];
%     D = asl_dictionary(CBF_Dict,deltat_Dict,'none');
%     [d,k] = size(D);
%     % Normalize the dictionary
%     AmplitudeD = zeros(k,1);
%     for i=1:k
%         AmplitudeD(i) = norm(D(:,i));
%         D(:,i) = D(:,i)/norm(D(:,i));
%     end
% end
% D(x<0,:) = [];
% x(x<0) = [];
distance = (x'*D)./(AmplitudeD+eps)';
ind = find(abs(distance) >= max(abs(distance)));
% ind = ind(1);
f = distance(ind)./AmplitudeD(ind)';
corPoint = intersect(find(f>0),find(f<200));
if ~isempty(corPoint)
corPoint = corPoint(1);
CBF = f(corPoint);

DT = deltat_Dict(ind(corPoint));
else
    CBF = 0;
    DT = 0;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
normD = repmat(sqrt(sum(D.^2,1)),size(D,1),1)+eps;
Dictionary =  [D./normD,eye(length(x))];
% sparseCoef = SolveBP(Dictionary,x,size(Dictionary,2),4,1e-2);
sparseCoef = bcs_rvm_r1(Dictionary,x,1e-2,1e-8);


CBF = sparseCoef(1:size(D,2));
DT = sparseCoef(end-length(x)+1:end);

figure(1),subplot(2,1,1);
plot(sparseCoef)
subplot(2,1,2);
plot(x,'o');hold on;
plot(D./normD*CBF,'r-');
hold off;
end